package jp.dev7.enchant.tot.controller.test;

import java.util.Map;

import jp.dev7.enchant.tot.controller.AbsJsonpController;
import jp.dev7.enchant.tot.service.IssueIdService;

import com.google.appengine.api.channel.ChannelService;
import com.google.appengine.api.channel.ChannelServiceFactory;
import com.google.appengine.repackaged.com.google.common.collect.Maps;

public class ConnectController extends AbsJsonpController {

    private IssueIdService issueIdService = new IssueIdService();

    private ChannelService channelService = ChannelServiceFactory
        .getChannelService();

    @Override
    protected Object exec() throws Exception {

        String userId = issueIdService.issue();
        String token = channelService.createChannel(userId);

        Map<String, Object> result = Maps.newHashMap();
        result.put("userId", userId);
        result.put("token", token);

        return result;
    }
}
